package com.snk.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.snk.common.config.Cache;
import com.snk.common.utils.ObjectMapperUtil;
import com.snk.mapper.UserMapper;
import com.snk.pojo.User;
import com.snk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;


import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public String doLogin(String username, String password) {
        //根据账户查询用户是否存在
        System.out.println(username+"=service="+password);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        User user=userMapper.selectOne(queryWrapper);
        System.out.println("用户信息查询完毕");
        System.out.println("输出用户信息"+user);//输出用户信息
        if (user!=null){
            System.out.println("用户存在");
            user.setPassword(password);
            String md5Pass =
                    DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
            user.setPassword(md5Pass);
            System.out.println("输出用户信息"+user);//输出用户信息
            QueryWrapper<User>queryWrapper1=new QueryWrapper<>(user);
            User userDB=userMapper.selectOne(queryWrapper1);
            System.out.println(userDB);
            if (userDB!=null){
                System.out.println("密码正确");
                String userId=user.getId().toString();
                System.out.println("用户Json数据="+userId);
                return userId;
            }
        }
        return null;
    }
}
